package com.example.zwl.controller;

import com.example.zwl.dao.persondao;
import com.example.zwl.pojo.person;
import com.example.zwl.pojo.student;
import com.example.zwl.service.Studentservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;


import java.io.File;

@Controller
public class XiuController {
    @Autowired
    Studentservice studentservice;
    @Autowired
    persondao psd;

    @GetMapping("/delete/{ID}")
    public String delete(@PathVariable("ID") Integer id) {
        studentservice.delete(id);
        return "redirect:/msg";
    }

    @GetMapping("/xiugai/{ID}")
    public String xiu(@PathVariable("ID") Integer id, Model model) {
        student s = studentservice.cha(id);
        model.addAttribute("mss", s);
        return "xiu";
    }
    @PostMapping("/update")
    public String update(student stu){
        studentservice.edit(stu);
        return "redirect:/msg";
    }
    @GetMapping("/up/{username}")
    public String up(@PathVariable("username")String username, Model model){
        person per=psd.getbyname(username);
        model.addAttribute("mg",per);
        return "gerenmsg";
    }
    @PostMapping("/upload")
    public String upload(@RequestParam("username")String username,@RequestParam("nichen")String nichen, File image){
        psd.add(new person(username,nichen,image));
        return "redirect:/msg";
    }
}

